package com.efuture.vdrp.android.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UnitsServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("gbk");
		response.setCharacterEncoding("gbk");
		PrintWriter out = response.getWriter();

		String unitName = request.getParameter("unitName");
		String action = request.getParameter("action");
		MySQL my = new MySQL();
		if (action.trim().equals("cxu")) {
			ArrayList al = new ArrayList();
			al = my.getUnitname();
			for (int i = 0; i < al.size(); i++) {
				out.println(al.get(i));
				out.flush();
			}
		} else if (action.trim().equals("unitadd")) {
			String unitname1 = request.getParameter("unitname").trim();
			String unitperson = request.getParameter("unitperson");
			String unitaddress = request.getParameter("unitaddress");
			String unitphone = request.getParameter("unitphone");
			String str = my.unitadd(unitname1, unitaddress, unitphone,
					unitperson);
			System.out.println(str + "OOOOOOOOOO");
			out.println(str);
			out.flush();
			out.close();
		} else if (action.trim().equals("deleteunit")) {
			String str = my.deleteunit(unitName);
			out.println(str);
			out.flush();
			out.close();
		} else if (action.trim().equals("unitupdate")) {
			String unitname1 = request.getParameter("unitname").trim();
			String unitperson = request.getParameter("unitperson");
			String unitaddress = request.getParameter("unitaddress");
			String unitphone = request.getParameter("unitphone");
			String str = my.unitupdate(unitname1, unitaddress, unitphone,
					unitperson);
			out.println(str);
			out.flush();
		} else if (action.trim().equals("seletall")) {
			String unitname = request.getParameter("nameunit").trim();
			System.out.println(unitname + "{{{{{{{{{{{{");
			StringBuffer a = new StringBuffer();
			a = my.unitall(unitname);
			out.println(a.toString());
			out.flush();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
